package leecode

import "fmt"

func getHint(secret string, guess string) string {
	hashSecret := make(map[byte]int) //key为字符 , value为字符出现的位置
	hashGuess := make(map[byte]int)
	b, c := 0, 0
	for i := 0; i < len(secret); i++ {
		//统计公牛数量
		if guess[i] == secret[i] {
			b++ //相等
		} else {
			hashSecret[secret[i]]++
			hashGuess[guess[i]]++
		}
	}
	for str, countS := range hashSecret {
		//剩余字符中母牛的数量
		countG, _ := hashGuess[str]
		if countS <= countG {
			c = c + countS
		} else {
			c = c + countG
		}
	}
	result := fmt.Sprintf("%vA%vB", b, c)
	return result
}
